package com.category.dao.impl.ibatis;

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.category.dao.RegionDao;
import com.category.meta.Region;
public class RegionDaoImpl extends SqlMapClientDaoSupport implements RegionDao {
	/**
	 * (non-Javadoc)
	 * 
	 * @see com.category.dao.RegionDao#insertRegion(com.category.meta.Region)
	 */
	public Long insertRegion(Region region) {
		Object newKey = this.getSqlMapClientTemplate().insert("region.insertRegion", region);
		return (Long)newKey;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.category.dao.RegionDao#deleteRegionById(java.lang.Long)
	 */
	public int deleteRegionById(Long id) {
		Region key = new Region();
		key.setId(id);
		int rows = this.getSqlMapClientTemplate().delete("region.deleteRegionById", key);
		return rows;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.category.dao.RegionDao#selectRegionById(java.lang.Long)
	 */
	public Region selectRegionById(Long id) {
		Region key = new Region();
		key.setId(id);
		Region result = (Region) this.getSqlMapClientTemplate().queryForList(
				"region.getRegionById", key);
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.category.dao.RegionDao#selectRegionsByFatherid(long)
	 */
	@SuppressWarnings("unchecked")
	public List<Region> selectRegionsByFatherid(long fatherid) {
		Region fidKey = new Region();
		fidKey.setFatherId(fatherid);
		return this.getSqlMapClientTemplate().queryForList("region.selectRegionsByFatherid", fidKey);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.category.dao.RegionDao#updateRegionById(com.category.meta.Region)
	 */
	public int updateRegionById(Region region) {
		int rows = this.getSqlMapClientTemplate().update("region.updateRegionById", region);
		return rows;
	}

}
